import 'dart:io';

import 'package:elec_communication_protocol/elec_communication_protocol.dart';

class Interface with DeviceControlInterface {
  DeviceControlService service;

  @override
  void onConnected(bool isNeedBound) {
    print('设备已成功连接，是否绑定: ${!isNeedBound}');
    if (isNeedBound) {
	    print('需要绑定设备，进行绑定');
    	service.bindAccountId().then((value) {
    		print(value);
	    });
    }
    else {
    	print('设备已经绑定成功，无需再次进行绑定');
    	// 推送计划
//	    service.pushSchedule('a123456', true).listen((event) {
//	    	print(event);
//	    });
//	    service.configDeviceName('abc ').then(print);
//    service.factoryReset().then(print);
        service.configInterWeb('https://tv.cctv.com/live/index.shtml?spm=C96370.PsikHJQ1ICOX.Ed1mZ1ZLksba.1').then(print);
    }

  }

  @override
  void onError(dynamic e) {
    print('发生异常: $e');
  }

  @override
  void onRefused() {
    print('握手被拒绝');
  }
}

void main() async {
	final interface = Interface();
	final service = DeviceControlService('abcd', interface);
    interface.service = service;
    service.start('192.168.0.135');

//	final socket = await Socket.connect('192.168.0.193', 10087).then((value) {
//		print('success');
//	}, onError: (e) {
//		print('失败');
//	});
//
//	await Future.delayed(const Duration(seconds: 10));

}
